/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-11-09 16:34:03
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2023-11-10 13:53:41
 * @FilePath: /three-react/src/pages/CurveGeometry/Line1.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useEffect, useRef } from "react"
import createRender from '@/createRender';
import * as THREE from 'three'


const state = {}
export default function Page() {

  const container = useRef(null);
  useEffect(() => {
    if (!state.isMounted) {
      createRender(container)(render);
      state.isMounted = true;
    }
  }, [])



  function render(scene) {


    // 一组二维向量表示一个多边形轮廓坐标
    const shape = new THREE.Shape([
      new THREE.Vector2(0,0),
      new THREE.Vector2(20,0),
      new THREE.Vector2(20,20),
      new THREE.Vector2(0,20),
    ])

    // 三维样条曲线
    const curve = new THREE.CatmullRomCurve3([
        new THREE.Vector3( -10, -50, -50 ),
        new THREE.Vector3( 10, 0, 0 ),
        new THREE.Vector3( 8, 50, 50 ),
        new THREE.Vector3( -5, 0, 100)
    ])

    const geometry = new THREE.ExtrudeGeometry(shape, {
      steps: 100,
      extrudePath: curve,
    })


    const material = new THREE.MeshLambertMaterial({
      color: 0x00ffff,
      side: THREE.DoubleSide,
   
    });
    const mesh = new THREE.Mesh(geometry, material);


    scene.add(mesh);
  }

  return (
    <div id="container" className="full container" ref={container}></div>
  )
}